package com.cg.controller;

import com.cg.client.SystemClient;
import com.cg.dto.Result;
import com.cg.entity.Source;
import com.cg.vo.MenuAllVo;
import com.cg.vo.SourceForRoleVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName SourceController
 * @Description 权限
 * @Author CG
 * @Date 2023/12/4 9:40
 **/
@RestController
@RequestMapping("/source")
public class SourceController {


    @Resource
    private SystemClient systemClient;

    /**
     * 创建权限
     * @param source
     * @return
     */
    @PostMapping("/createSource")
    Result createSource(@RequestBody Source source){
        return systemClient.createSource(source);
    }


    /**
     * 通过角色id获取角色信息
     * @param roleId
     * @return
     */
    @PostMapping("/queryAllSource")
    public Result<SourceForRoleVo> querySourceBySourceId(Integer roleId){
        return systemClient.querySourceBySourceId(roleId);
    }


    /**
     * 加载所有的以及二级菜单权限  
     */
    @PostMapping("/queryMenuAll")
    public Result<List<MenuAllVo>> queryMenuAll(){
        return systemClient.queryMenuAll();
    }


    /**
     * 验证权限是否存在
     * @param url
     * @return
     */
    @GetMapping("/checkSourceUrl")
    public Result checkSourceUrl(String url){
        return systemClient.checkSourceUrl(url);
    }

    /**
     * 删除权限
     */
    @GetMapping("/removeSource")
    public Result removeSource(Integer sourceId){
        return systemClient.removeSource(sourceId);
    }


    /**
     * 修改权限的名称
     * @param source
     * @return
     */
    @PostMapping("/updateSourceName")
    public Result updateSourceName(Source source){
        return systemClient.updateSourceName(source);
    }
}
